{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>数据库还原</h5>
                <div class="ibox-tools">
                    <a class="collapse-link">
                        <i class="fa fa-chevron-up"></i>
                    </a>
                </div>
            </div>
            <div class="ibox-content">
                <div class="row">
                    <div class="col-sm-12">
                        <div  class="col-sm-2" style="width:100px;">
                            <div class="input-group" >
                                <button class="btn btn-outline btn-danger" href="javascript:;" id="batchDel" >
                                    <i class="fa fa-trash-o"></i> 批量删除
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <form id="export-form" method="post" action="{:url('export')}">
                    <table class="footable table table-stripped toggle-arrow-tiny" data-page-size="{:config('pages')}" data-limit-navigation="5" >
                        <thead>
                        <tr  class="long-tr">
                            <th data-toggle="true"><span style="margin-left:25px;"><input class="i-checks checkbox check-all"  type="checkbox"></span></th>
                            <th>备份名称</th>
                            <th>卷数</th>
                            <th>压缩</th>
                            <th>数据大小</th>
                            <th>备份时间</th>
                            <th>状态</th>
                            <th data-hide="all" width="100">备份表</th>
                            <th data-hide="all">表数量</th>
                            <th data-hide="all">备份人</th>
                            <th data-hide="all">日期</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                            {notempty name="data"}
                                {volist name="data" id="vo"}
                                <tr class="long-td">
                                    <td>
                                        <input class="ids i-checks"  type="checkbox" name="ids[]" value="{$vo.time|date='Ymd-His',###}" id="{$vo.time|date='Ymd-His',###}zt">
                                    </td>
                                    <td>{$vo.time|date='Ymd-His',###}</td>
                                    <td>{$vo.part}</td>
                                    <td>{$vo.compress}</td>
                                    <td>{$vo.size|format_bytes}</td>
                                    <td>{$key}</td>
                                    <td>-</td>
                                    <td>
                                        {notempty name="$vo.table"}
                                            {foreach name="$vo.table" item="v" key="k"}
                                                <span>【{$v}】</span><br>
                                            {/foreach}
                                        {else/}
                                            ???
                                        {/notempty}
                                    </td>
                                    <td>{:count($vo.table)}张</td>
                                    <td>{$vo.who}管理员</td>
                                    <td>{$vo.time|date='Y.m.d',###}</td>
                                    <td>
                                        <a class="btn btn-primary btn-xs btn-outline db-import" href="{:url('revert',['time'=>$vo['time']])}">还原</a>
                                        <a class="btn btn-danger btn-xs btn-outline" href="javascript:;" onclick="dataDel(this,{$vo['time']})" >删除</a>
                                    </td>
                                </tr>
                                {/volist}
                            {else /}
                                <td colspan="7" class="text-center"> 暂无备份数据</td>
                            {/notempty}
                        </tbody>
                        <tfoot>
                            <tr>
                                <td colspan="10">
                                    <ul class="pagination pull-right"></ul>
                                </td>
                            </tr>
                        </tfoot>
                    </table>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- End Panel Other -->
{include file="public/footer" /}
<script type="text/javascript">
    //全选的实现
    $('.check-all').on('ifChecked', function (event) {
        $('input[name="ids[]"]').iCheck('check');
    });
    $('.check-all').on('ifUnchecked', function (event) {
        $('input[name="ids[]"]').iCheck('uncheck');
    });

    //还原数据
    $(function () {
        $(".db-import").click(function () {
            var self = this, status = ".";
            $(self).attr('disabled','disabled');
            $(self).next().attr('disabled','disabled');
            $.get(self.href, success, "json");
            window.onbeforeunload = function () { return "正在还原数据库，请不要关闭！";};
            return false;
            function success(data) {
                if (data.code) {
                    if (data.data.gz) {
                        // data.msg += status;
                        data.msg += '<i class="fa fa-refresh fa-spin"></i>';
                        // if (status.length === 5) {
                        //     status = ".";
                        // } else {
                        //     status += ".";
                        // }
                    }
                    $(self).parent().prev().prev().prev().prev().prev().html(data.msg);
                    if(data.data == 'success'){
                        $(self).parent().prev().prev().prev().prev().prev().css('color','#1BB394');
                        $(self).removeAttr('disabled','');
                        $(self).next().removeAttr('disabled','');
                    }
                    if (data.data.part) {
                        $.get(self.href, {"part": data.data.part, "start": data.data.start}, success, "json");
                    } else {
                        window.onbeforeunload = function () {return null;};
                    }
                }
            }
        });
    });

    //删除备份
    function dataDel(obj,id){
        // wk.confirm(id,'{:url("delData")}');
        layer.confirm('确认删除此备份?', {icon: 3, title:'提示'}, function(index){
            //do something
            $.getJSON('./delData', {'id' : id}, function(res){
                if(res.code == 200){
                    layer.msg(res.msg,{icon:1,time:1500,shade: 0.1},function(index){
                        layer.close(index);
                        // window.location.href="{:url('menu/index')}";
                        $(obj).parents("tr").remove();
                    });
                }else if(res.code == 100){
                    wk.error(res.msg,2,'');
                }
            });

            layer.close(index);
        })
    }
    //批量删除
    $('#batchDel').on('click',function(){
        layer.confirm('确认批量删除备份文件吗?', {icon: 3, title:'提示'}, function(index){
            $.ajax({
                url: "{:url('batchDelData')}",
                type: "post",
                dataType: "json",
                data: $("#export-form").serialize(),
                success: function (res) {
                    if(res.code == 200){
                        wk.success(res.msg,1,'');
                        if (res.data != "") {
                            $.each(res.data, function (index, item) {
                                $('#' + item + 'zt').parents("tr").remove();
                            })
                        }
                    } else if (res.code == 100){
                        wk.error(res.msg,2,'');
                    }
                }
            });
            layer.close(index);
        })
    })
</script>
<script>
    $(document).ready(function(){$(".footable").footable();$(".footable2").footable()});
</script>
</body>
</html>